﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace PressMenu2
{
    class MuiTen : GameObject
    {
        int speed = 10;
        Vector2 v = new Vector2();
        bool fired = false;
        public MuiTen(int id, int player) : base(id,player)
        {
            texture = MyResource.tMuiTen[id];
            Position = new Vector2(cDef.TAM.X, cDef.WindowHeight);
            rectangle = new Rectangle((int)Position.X, (int)Position.Y, texture.Width, texture.Height);
            this.Blood = 5;
        }

        public override int Update(GameTime gameTime, MyInput input)
        {
            if (Blood <= 0)
                return -1;

            if (input.Mouse.IsLeftClick())
            {
                Fire();
                return 1;
            }
            else
            {
                if (fired != true)
                {
                    float dx = input.Mouse.X - cDef.TAM.X;
                    float dy = input.Mouse.Y - cDef.TAM.Y;
                    if (dy != 0)
                        Angle = -(float)Math.Atan(dx / dy);
                }
            }

            if (fired)
            {
                if ((this.Position.X < cDef.WindowWidth + v.X) && (this.Position.X > -v.X))
                {
                    if (this.Position.Y > -v.Y)
                    {
                        this.Position = this.Position + new Vector2(v.X, v.Y);
                    }
                    else
                        return -1; // huy
                }
                else
                    return -1;
            }
            return 0;
        }

        public void Fire()
        {
            if (this.fired == false)
            {
                this.fired = true;
             //   Angle = cDef.angle;
            }
        }

        public override float Angle
        {
            get { return angle; }
            set { 
                angle = value;
                v.X = (float)(speed * Math.Sin(angle));
                v.Y = -(float)(speed * Math.Cos(angle));

            }
        }
    }
}
